<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: mslaria $ ($Date: 2007/07/26 09:48:59 $)
// $RCSfile: staff_viewticket.php,v $ : $Revision: 1.45 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

if ($_SWIFT["staff"]["t_entab"] == "0")
{
	echo '<font face="Verdana, Arial, Helvetica" size="2" color="red"><b>'.$_SWIFT["language"]["nopermission"].'</b></font>';
	exit;
}

require_once ("./includes/functions_html.php");
require_once ("./includes/data_mimelist.php");
$grid = new Grid();
$template->loadLanguageSection("staff_tickets");
require_once ("./modules/tickets/functions_ticketsui.php");

define("CUSTOMFIELD_STAFFUSERTICKET",9);
/**
* ###############################################
* VIEW TICKET
* ###############################################
*/
if ($eventaction == "viewticket") {
	require_once ("./modules/tickets/functions_ticketmain.php");
	$_ticketobj =& new TicketMain($_REQUEST["ticketid"]);

	if($_SWIFT["staff"]["tcanviewall"] != 1 && $_ticketobj->ticket["ownerstaffid"] != $_SWIFT["staff"]["staffid"])
	{
		echo $_SWIFT["language"]["errorticketaccess"];
		exit;
	}

	// First get the actual ticket.
	$_loadresult = $_ticketobj->loadTicketDisplay();

	if (!$_loadresult)
	{
		printRedirect($_SWIFT["language"]["invalidticket"], "index.php?_m=tickets&_a=manage&invalidticket=1");
		exit;
	}
	
	$_ticketobj->lockTicket($_SWIFT["staff"]["staffid"]);
	$_ticket = &$_ticketobj->ticket;

	if ($_SWIFT["staff"]["texport"] != "0")
	{
		$template->assign("canexport", true);
	} else {
		$template->assign("canexport", false);
	}

	if ($_REQUEST["usecharset"] == 1 && !empty($_ticket["charset"]))
	{
		$_SWIFT["language"]["charset"] = $_ticket["charset"];
		$template->_vars["language"]["charset"] = $_ticket["charset"];
	}

	if (!empty($_REQUEST["ticketsearchid"]))
	{
		$_SWIFT["ticketsearch"] = $dbCore->queryFetch("SELECT * FROM `". TABLE_PREFIX ."ticketsearches` WHERE `ticketsearchid` = '". intval($_REQUEST["ticketsearchid"]) ."';");
	}

	if (isset($_GET["followupresult"]) && $_GET["followupresult"] == 0)
	{
		$errormessage = $_SWIFT["language"]["followupfail"];
	} else if ($_GET["followupresult"] == 1) {
		$infomessage = $_SWIFT["language"]["followupsuccess"];
	}

	renderTicketTree();
	$_gridset = &$_SWIFT["ticketgridcache"][$_SWIFT["staff"]["staffid"]];

	$template->assign("isviewticket", true);
	$template->assign("ticketid", $_ticket["ticketid"]);
	$template->assign("slaplans", $_SWIFT["slaplancache"]);
	$template->assign("slaplancount", count($_SWIFT["slaplancache"]));
	$template->assign("ticketslaplanid", $_ticket["ticketslaplanid"]);
	$template->assign("userslaplanid", $_ticket["user"]["userslaplanid"]);
	$template->assign("calendar", true);
	$template->assign("spellcheck", true);

	$_ticket["fticketid"] = iif($_SWIFT["settings"]["t_eticketid"]=="seq",$_ticket["ticketid"], $_ticket["ticketmaskid"]);

	$interface->staffHeader($_SWIFT["language"]["tickets"] ." &gt; ".$_ticket["fticketid"], 2);

	$navtitled = htmlspecialchars($_ticket["subject"])." (". $_ticket["fticketid"] .")";

	if (!empty($_REQUEST["ticketsearchid"]) && empty($_SWIFT["ticketsearch"]["ticketfilterid"]))
	{
		$nav = '<a href="index.php?_m=tickets&_a=manage" title="'.$_SWIFT["language"]["manage"].'">'.$_SWIFT["language"]["manage"].'</a> &raquo; <a href="index.php?_m=tickets&_a=manage&ticketsearchid='. intval($_REQUEST["ticketsearchid"]) .'" title="'.addslashes($_SWIFT["language"]["searchquery"]).'">'.$_SWIFT["language"]["searchquery"].'</a> &raquo; <a href="index.php?_m=tickets&_a=viewticket&ticketid='. intval($_ticket["ticketid"]) .'" title="'.addslashes($_ticket["fticketid"]).'">'.$navtitled.'</a>';
	} else if (!empty($_REQUEST["ticketsearchid"]) && !empty($_SWIFT["ticketsearch"]["ticketfilterid"])) {
		$nav = '<a href="index.php?_m=tickets&_a=manage" title="'.$_SWIFT["language"]["manage"].'">'.$_SWIFT["language"]["manage"].'</a> &raquo; <a href="index.php?_m=tickets&_a=manage&ticketsearchid='. intval($_REQUEST["ticketsearchid"]) .'" title="'.addslashes($_SWIFT["ticketfiltercache"][$_SWIFT["ticketsearch"]["ticketfilterid"]]["title"]).'">'.$_SWIFT["ticketfiltercache"][$_SWIFT["ticketsearch"]["ticketfilterid"]]["title"].'</a> &raquo; <a href="index.php?_m=tickets&_a=viewticket&ticketid='. intval($_ticket["ticketid"]) .'" title="'.addslashes($_ticket["fticketid"]).'">'.$navtitled.'</a>';
	} else if (!empty($_REQUEST["ticketlabelid"])) {
		$nav = '<a href="index.php?_m=tickets&_a=manage" title="'.$_SWIFT["language"]["manage"].'">'.$_SWIFT["language"]["manage"].'</a> &raquo; <a href="index.php?_m=tickets&_a=manage&ticketlabelid='. intval($_REQUEST["ticketlabelid"]) .'">'.htmlspecialchars($_SWIFT["ticketlabelcache"][$_REQUEST["ticketlabelid"]]["title"]).'</a> &raquo; <a href="index.php?_m=tickets&_a=viewticket&ticketid='. intval($_ticket["ticketid"]) .'" title="'.addslashes($_ticket["fticketid"]).'">'.$navtitled.'</a>';
	} else {
		$nav = '<a href="index.php?_m=tickets&_a=manage" title="'.$_SWIFT["language"]["manage"].'">'.$_SWIFT["language"]["manage"].'</a> &raquo; <a href="index.php?_m=tickets&_a=manage&departmentid='. intval($_ticket["departmentid"]) .'" title="'.addslashes($_SWIFT["departmentcache"][$_ticket["departmentid"]]["title"]).'">'.$_SWIFT["departmentcache"][$_ticket["departmentid"]]["title"].'</a> &raquo; <a href="index.php?_m=tickets&_a=manage&departmentid='. intval($_ticket["departmentid"]) .'&ticketstatusid='. intval($_ticket["ticketstatusid"]) .'" title="'.addslashes($_SWIFT["statuscache"][$_ticket["ticketstatusid"]]["title"]).'">'.$_SWIFT["statuscache"][$_ticket["ticketstatusid"]]["title"].'</a> &raquo; <a href="index.php?_m=tickets&_a=viewticket&ticketid='. intval($_ticket["ticketid"]) .'" title="'.addslashes($_ticket["fticketid"]).'">'.$navtitled.'</a>';
	}

	if ($_GET["flagconfirm"] == 1)
	{
		$_SWIFT["infomessage"] = sprintf($_SWIFT["language"]["flagconfirm"], $_ticket["fticketid"]);
	} else if ($_GET["dueconfirm"] == 1) {
		$_SWIFT["infomessage"] = sprintf($_SWIFT["language"]["dueconfirm"], $_ticket["fticketid"]);
	} else if ($_GET["noteconfirm"] == 1) {
		$_SWIFT["infomessage"] = sprintf($_SWIFT["language"]["noteconfirm"], $_ticket["fticketid"]);
	} else if ($_GET["slatconfirm"] == 1) {
		$_SWIFT["infomessage"] = sprintf($_SWIFT["language"]["slatconfirm"], $_ticket["fticketid"]);
	} else if ($_GET["slauconfirm"] == 1) {
		$_SWIFT["infomessage"] = sprintf($_SWIFT["language"]["slauconfirm"], htmlspecialchars($_ticket["user"]["fullname"]));
	} else if ($_GET["notedconfirm"] == 1) {
		$_SWIFT["infomessage"] = $_SWIFT["language"]["notedconfirm"];
	}else if ($_GET["cfdelconfirm"] == 1) {
		$_SWIFT["infomessage"] = $_SWIFT["language"]["cfdelconfirm"];
	} else if ($_GET["tcconfirm"] == 1) {
		$_SWIFT["infomessage"] = sprintf($_SWIFT["language"]["tcconfirm"], htmlspecialchars($_ticket["fticketid"]));
	} else if ($_GET["delpresult"] == "0" || $_GET["delpresult"] == "-1") {
		$_SWIFT["errormessage"] = sprintf($_SWIFT["language"]["delpostfail"], htmlspecialchars($_ticket["fticketid"]));
	} else if ($_GET["delpresult"] == "1") {
		$_SWIFT["infomessage"] = sprintf($_SWIFT["language"]["delpostconfirm"], htmlspecialchars($_ticket["fticketid"]));
	} else if ($_GET["replyerror"] == "1") {
		$_SWIFT["errormessage"] = sprintf($_SWIFT["language"]["replyerror"], htmlspecialchars($_ticket["fticketid"]));
	}

	$interface->staffNavBar($nav, "", 2);

	printInfoBox($_SWIFT["infomessage"]);
	printErrorBox($_SWIFT["errormessage"]);

	echo '<table cellspacing="0" cellpadding="0" border="0" width="100%" id="tickettableopt'. $_ticket["ticketid"] .'"><tr style="height: 1em"><td align="left"><div id="ticketopt'. $_ticket["ticketid"] .'"><ul id="tab">
	
	<li><a class="currenttab" href="#" onClick="this.blur(); return switchGridTab(\'ttgeneral\', \'tickets\');" id="ttgeneral" title="'. $_SWIFT["language"]["tabgeneral"] .'">'. $_SWIFT["language"]["tabgeneral"] .'</a></li>
	<li><a href="#" onClick="this.blur(); switchGridTab(\'ttpostreply\', \'tickets\'); document.replyform.replycontents.focus(); startTicketLock(\''. intval($_ticket["ticketid"]) .'\');" id="ttpostreply" title="'. $_SWIFT["language"]["tabpostreply"] .'">'. $_SWIFT["language"]["tabpostreply"] .'</a></li>';

	if ($_SWIFT["staff"]["tforward"] != "0")
	{
		echo '<li><a href="#" onClick="this.blur();switchGridTab(\'ttforward\', \'tickets\');if (!loadedStates[\'forward\']) {fetchData(\'forward\', \''. $_ticket["ticketid"] .'\', \''. intval($_REQUEST["ticketlabelid"]) .'\');}" id="ttforward" title="'. $_SWIFT["language"]["tabforward"] .'">'. $_SWIFT["language"]["tabforward"] .'</a></li>';
	}

	echo '<li><a href="#" onClick="this.blur();switchGridTab(\'ttfollowup\', \'tickets\');if (!loadedStates[\'followup\']) {fetchData(\'followup\', \''. $_ticket["ticketid"] .'\', \''. intval($_REQUEST["ticketlabelid"]) .'\');}" id="ttfollowup" title="'. $_SWIFT["language"]["tabfollowup"] .'">'. $_SWIFT["language"]["tabfollowup"] .'</a></li>';

	if ($_SWIFT["staff"]["tbilling"] != "0")
	{
		echo '<li><a href="#" onClick="this.blur(); switchGridTab(\'ttbilling\', \'tickets\');if (!loadedStates[\'billing\']) {fetchData(\'billing\', \''. $_ticket["ticketid"] .'\');}" id="ttbilling" title="'. $_SWIFT["language"]["billing"] .'">'. $_SWIFT["language"]["billing"] .'</a></li>';
	}

	$_total = $dbCore->queryFetch("SELECT COUNT(*) AS totalitems FROM `". TABLE_PREFIX ."tickets` WHERE `email` = '". $dbCore->escape($_ticket["email"]) ."';");
	$_tickethistorycount = intval($_total["totalitems"]);
	if ($_tickethistorycount > 0)
	{
		$_strhistorycount = ' <font color="#CF5D60">('. $_tickethistorycount .')';
	} else {
		$_strhistorycount = ' (0)';
	}

	echo '<li><a href="#" onClick="this.blur(); switchGridTab(\'ttaddnotes\', \'tickets\');if (!loadedStates[\'addnotes\']) {fetchData(\'addnotes\', \''. $_ticket["ticketid"] .'\', \''. intval($_REQUEST["ticketlabelid"]) .'\');}" id="ttaddnotes" title="'. $_SWIFT["language"]["tabaddnotes"] .'">'. $_SWIFT["language"]["tabaddnotes"] .'</a></li>
	<li><a href="#" onClick="this.blur(); switchGridTab(\'ttrelease\', \'tickets\');if (!loadedStates[\'release\']) {fetchData(\'release\', \''. $_ticket["ticketid"] .'\', \''. intval($_REQUEST["ticketlabelid"]) .'\');}" id="ttrelease" title="'. $_SWIFT["language"]["tabrelease"] .'">'. $_SWIFT["language"]["tabrelease"] .'</a></li>
	<li><a href="#" onClick="this.blur(); switchGridTab(\'tthistory\', \'tickets\');if (!loadedStates[\'history\']) {fetchData(\'history\', \''. $_ticket["email"] .'\');}" id="tthistory" title="'. $_SWIFT["language"]["tabhistory"] .'">'. sprintf($_SWIFT["language"]["tabhistorycnt"], $_strhistorycount) .'</a></li>';
	
	if ($module->isRegistered(MODULE_LIVESUPPORT) && !empty($_ticket["email"]))
	{
		$_total = $dbCore->queryFetch("SELECT COUNT(*) AS totalitems FROM `". TABLE_PREFIX ."chatobjects` WHERE `useremail` = '". $dbCore->escape($_ticket["email"]) ."';");
		$_chatcount = intval($_total["totalitems"]);
		if ($_chatcount > 0)
		{
			$_strchatcount = ' <font color="#CF5D60">('. $_chatcount.')';
		} else {
			$_strchatcount = ' <font color="gray">(0)</font>';
		}

		echo '<li><a href="#" onClick="this.blur(); switchGridTab(\'ttlschats\', \'tickets\');if (!loadedStates[\'lschats\']) {fetchData(\'lschats\', \''. "&email[]=".urlencode($_ticket["email"]) .'\');}" id="ttlschats" title="'. $_SWIFT["language"]["strchats"] .'">'. sprintf($_SWIFT["language"]["tabchats"], $_strchatcount) .'</a></li>';
	}

	echo '<li><a href="#" onClick="this.blur(); switchGridTab(\'ttlog\', \'tickets\');if (!loadedStates[\'auditlog\']) {fetchData(\'auditlog\', \''. $_ticket["ticketid"] .'\');}" id="ttlog" title="'. $_SWIFT["language"]["tablog"] .'">'. $_SWIFT["language"]["tablog"] .'</a></li>
	<li><a href="#" onClick="this.blur(); switchGridTab(\'ttedit\', \'tickets\');if (!loadedStates[\'edit\']) {fetchData(\'edit\', \''. $_ticket["ticketid"] .'\');}" id="ttedit" title="'. $_SWIFT["language"]["tabedit"] .'">'. $_SWIFT["language"]["tabedit"] .'</a></li>
	</ul></div></td></tr>'.SWIFT_CRLF;

	echo '<tr style="height: 1em"><td align="left">'.SWIFT_CRLF;

	// ======= GENERATE BASIC OPTIONS =======

	extract(generateTicketSelectBoxes($_ticket, '', true, 'generalform'));

	$_flagoptions .= '<option value="0" style="color:#919191"'. iif(!$_ticket["flagtype"], " selected") .'>'. $_SWIFT["language"]["unassigned"] .'</option>'.SWIFT_CRLF;
	$_flagoptions .= '<option value="'. FLAG_PURPLE .'" style="color:#A5587C"'. iif($_ticket["flagtype"]==FLAG_PURPLE, " selected") .'>'. $_SWIFT["language"]["purpleflag"] .'</option>'.SWIFT_CRLF;
	$_flagoptions .= '<option value="'. FLAG_RED .'" style="color:#CF5D60"'. iif($_ticket["flagtype"]==FLAG_RED, " selected") .'>'. $_SWIFT["language"]["redflag"] .'</option>'.SWIFT_CRLF;
	$_flagoptions .= '<option value="'. FLAG_ORANGE .'" style="color:#FF8C5A"'. iif($_ticket["flagtype"]==FLAG_ORANGE, " selected") .'>'. $_SWIFT["language"]["orangeflag"] .'</option>'.SWIFT_CRLF;
	$_flagoptions .= '<option value="'. FLAG_YELLOW .'" style="color:#FFC160"'. iif($_ticket["flagtype"]==FLAG_YELLOW, " selected") .'>'. $_SWIFT["language"]["yellowflag"] .'</option>'.SWIFT_CRLF;
	$_flagoptions .= '<option value="'. FLAG_BLUE .'" style="color:#5C83B4"'. iif($_ticket["flagtype"]==FLAG_BLUE, " selected") .'>'. $_SWIFT["language"]["blueflag"] .'</option>'.SWIFT_CRLF;
	$_flagoptions .= '<option value="'. FLAG_GREEN .'" style="color:#8BB467"'. iif($_ticket["flagtype"]==FLAG_GREEN, " selected") .'>'. $_SWIFT["language"]["greenflag"] .'</option>'.SWIFT_CRLF;
	$_flagselect = '<select name="tt_flagtype" class="swiftselect">'. $_flagoptions .'</select>'.SWIFT_CRLF;


	// ======= BEGIN GENERAL TAB =======
	$flagbgcolors = array(FLAG_PURPLE => "#A5587C", FLAG_ORANGE => "#FF8C5A", FLAG_GREEN => "#8BB467", FLAG_YELLOW => "#FFC160", FLAG_RED => "#CF5D60", FLAG_BLUE => "#5C83B4");
	$flagicons = array(FLAG_PURPLE => "icon_purpleflag.gif", FLAG_ORANGE => "icon_orangeflag.gif", FLAG_GREEN => "icon_greenflag.gif", FLAG_YELLOW => "icon_yellowflag.gif", FLAG_RED => "icon_redflag.gif", FLAG_BLUE => "icon_blueflag.gif");
	$flagtext = array(FLAG_PURPLE => $_SWIFT["language"]["purpleflag"], FLAG_ORANGE => $_SWIFT["language"]["orangeflag"], FLAG_GREEN => $_SWIFT["language"]["greenflag"], FLAG_YELLOW => $_SWIFT["language"]["yellowflag"], FLAG_RED => $_SWIFT["language"]["redflag"], FLAG_BLUE => $_SWIFT["language"]["blueflag"]);
	echo '<div id="tab_ttgeneral" style="DISPLAY: block;" class="tabcontent"><table border="0" cellpadding="0" cellspacing="1" width="100%" class="tborder">'.SWIFT_CRLF;
	printFormStart("generalform");

	$_duetime = "";
	if ($_ticket["duetime"] != 0)
	{
		if (DATENOW >= $_ticket["duetime"])
		{
			// Overdue
			$_duetime = '<span class=\'tickettextred\'>'.$_SWIFT["language"]["overdue"].'</span>';
		} else {
			$_duetime = strColorDate(($_ticket["duetime"]-DATENOW), true);
		}
	}

//	$_timeworked = strColorDate($_ticket["timeworked"]);

	$_labellist = $_ticketlabelidlist = array();
	if ($_ticket["islabeled"] == 1)
	{
		$_ticketobj->loadTicketLabels();
		foreach ($_ticketobj->ticket["labels"] as $key=>$val)
		{
			$_ticketlabelidlist[] = $val["ticketlabelid"];
			$_labellist[] = htmlspecialchars($_SWIFT["ticketlabelcache"][$val["ticketlabelid"]]["title"]);
		}
		$_labeltext = implode(", ",$_labellist);
	} else {
		$_labeltext = '<span class="darkredtext">'.$_SWIFT["language"]["unassigned"].'</span>';
	}

	unset($_labelselect);

	if (_is_array($_SWIFT["ticketlabelcache"]))
	{
		foreach ($_SWIFT["ticketlabelcache"] as $key=>$val)
		{
			if ($val["labeltype"] == SWIFTPUBLIC || ($val["labeltype"] == SWIFTPRIVATE && $val["staffid"] == intval($_SWIFT["staff"]["staffid"])))
			{
				$_labelselect .= '<label for="label'.$val["ticketlabelid"].'"><input type="checkbox" id="label'. $val["ticketlabelid"] .'" name="opt_ticketlabelid[]" value="'. $val["ticketlabelid"] .'"'. iif(in_array($val["ticketlabelid"], $_ticketlabelidlist), " checked") .' />'.htmlspecialchars($_SWIFT["ticketlabelcache"][$val["ticketlabelid"]]["title"]).'</label><BR />';
			}
		}
	}

	// ======= TICKET INFO + ESCALATION PATHS =======

	// Handle the Escalation Paths
	$_indent = $_titleshown = 0;
	if (count($_ticket["escalationpaths"]))
	{
		foreach ($_ticket["escalationpaths"] as $key=>$val)
		{
			$_escalationpathhtml .= '<tr><td align="left" valign="top" colspan="8" style="PADDING: 0px 0px 4px 0px;">';

			if ($_indent)
			{
				$_indentsize = $_indent*6;
				$_escalationpathhtml .= '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
				$_escalationpathhtml .= '<tr><td width="'. $_indentsize .'"><img src="'. $_SWIFT["themepath"].'space.gif" width="'. $_indentsize .'" height="1" border="0" /></td><td width="1"><img src="'. $_SWIFT["themepath"] .'linkdownarrow_red.gif" align="absmiddle" border="0" /></td><td>';
			}

			$_escalationpathhtml .= '<div class="ticketcboxpad"><div class="ticketescalationpath"><div class="ticketcboxsmall"><table border="0" cellpadding="0" cellspacing="1" width="100%">';

		if (empty($_titleshown))
		{
			$_escalationpathhtml .= '<tr class="escalationpathtitlerow"><td width="18"><img src="'. $_SWIFT["themepath"] .'space.gif" width="18" height="20" border="0" /></td><td align="center" width="15%">'. $_SWIFT["language"]["f_date"] .'</td><td width="15%" align="center">'. $_SWIFT["language"]["f_owner"] .'</td><td width="15%" align="center">'. $_SWIFT["language"]["f_department"] .'</td><td width="15%" align="center">'. $_SWIFT["language"]["f_ticketstatus"] .'</td><td width="15%" align="center">'. $_SWIFT["language"]["f_priority"] .'</td><td width="15%" align="center">'. $_SWIFT["language"]["f_slaplan"] .'</td><td width="15%" align="center">'. $_SWIFT["language"]["f_rule"] .'</td></tr>';
		}

		$_escalationpathhtml .= '<tr style="DISPLAY: ;" class="escalationpathrow"><td width="18"><img src="' .$_SWIFT["themepath"]. 'icon_escalationpath.gif" border="0" align="absmiddle" /></td><td align="center" width="15%">'. edate($_SWIFT["settings"]["dt_datetimeformat"], $val["dateline"]) .'</td><td align="center" width="15%"><span class="'. iif($val["ownerstaffid"]!=$_SWIFT["staff"]["staffid"], "darkredtext", "smalltext") .'">'. iif(!$val["ownerstaffid"],$_SWIFT["language"]["unassigned"], htmlspecialchars($_SWIFT["staffcache"][$val["ownerstaffid"]]["fullname"])) .'</span></td><td align="center" width="15%">'. htmlspecialchars($_SWIFT["departmentcache"][$val["departmentid"]]["title"]) .'</td><td align="center" width="15%"><font color=\''. $_SWIFT["statuscache"][$val["ticketstatusid"]]["statuscolor"] .'\'>'. htmlspecialchars($_SWIFT["statuscache"][$val["ticketstatusid"]]["title"]) .'</font></td><td align="center" width="15%"><font color=\''. $_SWIFT["prioritycache"][$val["priorityid"]]["frcolorcode"] .'\'>'. htmlspecialchars($_SWIFT["prioritycache"][$val["priorityid"]]["title"]) .'</font></td><td align="center" width="15%">'. htmlspecialchars($_SWIFT["slaplancache"][$val["slaplanid"]]["title"]) .'</td><td align="center" width="15%">'. htmlspecialchars($_SWIFT["escalationrulecache"][$val["escalationruleid"]]["title"]) .'</td></tr>';

			$_escalationpathhtml .= '</table></div></div></div>';

			if ($_indent)
			{
				$_escalationpathhtml .= '</td></tr></table>';
			}

			$_escalationpathhtml .= '</td></tr>';

			$_titleshown = 1;
			$_indent++;
		}
	}

	echo $_escalationpathhtml;

	if (count($_ticket["escalationpaths"]))
	{
		echo '<tr><td align="left" valign="top" colspan="8" style="PADDING: 0px 0px 4px 0px;">';

		if ($_indent)
		{
			$_indentsize = $_indent*6;
			echo '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
			echo '<tr><td width="'. $_indentsize .'"><img src="'. $_SWIFT["themepath"].'space.gif" width="'. $_indentsize .'" height="1" border="0" /></td><td width="1"><img src="'. $_SWIFT["themepath"] .'linkdownarrow_red.gif" align="absmiddle" border="0" /></td><td>';
		}

		echo '<div class="ticketcboxpad"><div class="ticketescalationpathblue"><div class="ticketcboxsmall"><table border="0" cellpadding="0" cellspacing="1" width="100%">';
	}

	echo '<tr class="tabletitlerow"><td width="18"><img src="'. $_SWIFT["themepath"] .'space.gif" width="18" height="20" border="0" /></td><td align="center">'. $_SWIFT["language"]["f_ticketid"] .'</td><td width="15%" align="center">'. $_SWIFT["language"]["f_owner"] .'</td><td width="15%" align="center">'. $_SWIFT["language"]["f_department"] .'</td><td width="15%" align="center">'. $_SWIFT["language"]["f_ticketstatus"] .'</td><td width="15%" align="center">'. $_SWIFT["language"]["f_priority"] .'</td><td width="15%" align="center">'. $_SWIFT["language"]["f_duedate"] .'</td><td width="15%" align="center">'. $_SWIFT["language"]["labels"] .'</td></tr>';
	echo '<tr id="tickettext" style="DISPLAY: ;" class="'. getRowBG() .'"><td bgcolor="'. $flagbgcolors[$_ticket["flagtype"]] .'">'.iif(!empty($_ticket["flagtype"]), '<img src=\''. $_SWIFT["themepath"]. $flagicons[$_ticket["flagtype"]] .'\' width="18" height="20" border=\'0\' />', '<img src=\''. $_SWIFT["themepath"] .'icon_flagblank.gif\' width=\'18\' height=\'20\' border=\'0\' />').'</td><td align="center">'. $_ticket["fticketid"] .'</td><td align="center" class="tdpointer" onClick="javascript:displayTicketEdit();"><span class="'. iif($_ticket["ownerstaffid"]!=$_SWIFT["staff"]["staffid"], "darkredtext", "smalltext") .'">'. iif(!$_ticket["ownerstaffid"],$_SWIFT["language"]["unassigned"], htmlspecialchars($_SWIFT["staffcache"][$_ticket["ownerstaffid"]]["fullname"])) .'</span></td><td class="tdpointer" align="center" onClick="javascript:displayTicketEdit();">'. htmlspecialchars($_SWIFT["departmentcache"][$_ticket["departmentid"]]["title"]) .'</td><td class="tdpointer" align="center" onClick="javascript:displayTicketEdit();"><font color=\''. $_SWIFT["statuscache"][$_ticket["ticketstatusid"]]["statuscolor"] .'\'>'. htmlspecialchars($_SWIFT["statuscache"][$_ticket["ticketstatusid"]]["title"]) .'</font></td><td class="tdpointer" align="center" onClick="javascript:displayTicketEdit();"><font color=\''. $_SWIFT["prioritycache"][$_ticket["priorityid"]]["frcolorcode"] .'\'>'. htmlspecialchars($_SWIFT["prioritycache"][$_ticket["priorityid"]]["title"]) .'</font></td><td class="tdpointer" align="center" onClick="javascript:displayTicketEdit();">'. $_duetime .'</td><td class="tdpointer" align="center" onClick="javascript:displayTicketEdit();">'. $_labeltext .'</td></tr>';

	extract(generateStatusSelectBox($_ticket["departmentid"], $_ticket["ticketstatusid"]));
	echo '<tr id="ticketedit" style="DISPLAY: none;" class="'. getRowBG() .'"><td bgcolor="'. $flagbgcolors[$_ticket["flagtype"]] .'">'.iif(!empty($_ticket["flagtype"]), '<img src=\''. $_SWIFT["themepath"]. $flagicons[$_ticket["flagtype"]] .'\' border=\'0\' />', '<img src=\''. $_SWIFT["themepath"] .'icon_flagblank.gif\' width=\'18\' height=\'20\' border=\'0\' />').'</td><td align="center">'. $_ticket["fticketid"] .'</td><td align="center">'. $_staffselect .'</td><td align="center">'. $_departmentselect .'</td><td align="center" nowrap><div id="updatestatusgeneralform"><img src="'. $_SWIFT["themepath"] .'loadingcircle.gif" id="generalformloading" border="0" align="absmiddle" style="display: none;" /> '. $_statusselect .'</div></td><td align="center">'. $_priorityselect .'</td><td align="center" nowrap><input type="text" name="opt_due" id="opt_due" size="12" readonly="1" value="'. iif($_ticket["duetime"]!="0", generateCalendarTimeline($_ticket["duetime"])) .'" class="swifttext" onclick="return showCalendar(\'opt_due\', \''. iif($_SWIFT["settings"]["dt_caltype"]=="us", "%m/%d/%Y", "%d/%m/%Y") .'\');" />&nbsp;<img src="'. $_SWIFT["themepath"] .'icon_duetime.gif" id="opt_duetrigger" style="cursor: pointer;" title="'. $title .'" align="absmiddle" onclick="return showCalendar(\'opt_due\', \''. iif($_SWIFT["settings"]["dt_caltype"]=="us", "%m/%d/%Y", "%d/%m/%Y") .'\');" /> &nbsp;<a href="javascript:void(0);" onclick="javascript:document.getElementById(\'opt_due\').value=\'\';"><img src="'. $_SWIFT["themepath"] .'icon_duetimeclear.gif" align="absmiddle" border="0" /></a></td><td align="center">'. $_labelselect .'</td></tr>';
	echo '<tr id="ticketsubmit" style="DISPLAY: none;"><td align="center" valign="top" colspan="8"><input type="submit" class="yellowbutton" name="submit" value="'. $_SWIFT["language"]["submit"] .'" />&nbsp;&nbsp;&nbsp;<input type="button" class="yellowbutton" name="cancel" onClick="javascript: hideTicketEdit();" value="'. $_SWIFT["language"]["cancel"] .'" /></td></tr>';

	if (count($_ticket["escalationpaths"]))
	{
		echo '</table></div></div></div>';

		if ($_indent)
		{
			echo '</td></tr></table>';
		}

		echo '</td></tr>';
	}

	if ($_SWIFT["staff"]["tcanviewall"] != 1 && $_ticketobj->ticket["ownerstaffid"] != $_SWIFT["staff"]["staffid"])
	{
		// do nothing...
	} else {
		$_lockthreshold = DATENOW-$_SWIFT["settings"]["t_locktimeout"];
		// Is ticket locked?
		if (!empty($_ticket["lockstaffid"]) && $_ticket["lockdateline"] > $_lockthreshold && $_ticket["lockstaffid"] != $_SWIFT["staff"]["staffid"])
		{
			$_lockdiff = DATENOW-$_ticket["lockdateline"];
			echo '<tr class="ticketnote"><td align="center" valign="top" colspan="8" class="smalltext"><img src="'. $_SWIFT["themepath"] .'icon_lock.gif" align="absmiddle" border="0" /> '. sprintf($_SWIFT["language"]["lockmsg"], $_SWIFT["staffcache"][$_ticket["lockstaffid"]]["fullname"], strColorDate($_lockdiff)) .'</td></tr>';
		}
	}
	// Charset diff
	if (!empty($_ticket["charset"]) && $_ticket["charset"] != $_SWIFT["language"]["charset"])
	{
		echo '<tr class="ticketnote"><td align="center" valign="top" colspan="8" class="smalltext"><img src="'. $_SWIFT["themepath"] .'icon_info.gif" align="absmiddle" border="0" /> <a href="index.php?_m=tickets&_a=viewticket&ticketid='. intval($_ticket["ticketid"]) .'&usecharset=1">'. $_SWIFT["language"]["charsetdiff"] .'</a></td></tr>';
	}
	
	foreach ($_ticket["notes"] as $key=>$val)
	{
		if ($val["forstaffid"] == 0 || $val["forstaffid"] == $_SWIFT["staff"]["staffid"])
		{
			if (empty($val["bystaffid"]))
			{
				$byname = $_SWIFT["language"]["alsystem"];
			} else {
				$byname = htmlspecialchars($_SWIFT["staffcache"][$val["bystaffid"]]["fullname"]);
			}
			echo '<tr><td align="left" valign="top" colspan="8" style="PADDING: 0px 0px 4px 0px;"><div class="ticketcboxpad"><div class="ticketnote"><div class="ticketcbox"><table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr><td width="1" align="left"><img src="'. $_SWIFT["themepath"] .'icon_topic'. iif($val["dateline"]>$_SWIFT["staff"]["lastvisit"], "yellow") .'.gif" border="0" /></td>
			<td align="left"><span class="smalltext">&nbsp;'. sprintf($_SWIFT["language"]["notetitleformat"], $byname, edate($_SWIFT["settings"]["dt_datetimeformat"], $val["dateline"]), strColorDate(DATENOW-$val["dateline"], true, true)) .'</span></td><td width="1" align="right"><a href="index.php?_m=tickets&_a=ticketactions&action=delticketnote&ticketid='. $_ticket["ticketid"] .'&ticketnoteid='. $val["ticketnoteid"] .'"><img src="'. $_SWIFT["themepath"] .'icon_ftrash.gif" border="0" /></a></td></tr>
			<tr><td colspan="3"><HR class="notehr"></td></tr>
			<tr class="ticketnotecontent"><td colspan="3"><span class="smalltext">'. getProcessedHTML($val["notes"]) .'</span></td></tr>
			</table></div></div></div></td></tr>';
		}
	}

	foreach ($_ticket["billing"] as $key=>$val)
	{
		echo '<tr><td align="left" valign="top" colspan="8" style="PADDING: 0px 0px 4px 0px;"><div class="ticketcboxpad"><div class="ticketbl"><div class="ticketcbox"><table border="0" cellpadding="0" cellspacing="0" width="100%">
		<tr><td width="1" align="left"><img src="'. $_SWIFT["themepath"] .'icon_topic'. iif($val["dateline"]>$_SWIFT["staff"]["lastvisit"], "purple") .'.gif" border="0" /></td>
		<td align="left"><span class="smalltext">&nbsp;'. sprintf($_SWIFT["language"]["billtitleformat"], htmlspecialchars($_SWIFT["staffcache"][$val["forstaffid"]]["fullname"]), edate(iif($_SWIFT["settings"]["dt_caltype"]=="us", "M d Y H:i", "d M Y H:i"), $val["dateline"])) .'</span></td><td width="1" align="right"><a href="index.php?_m=tickets&_a=ticketactions&action=delbillentry&ticketid='. $_ticket["ticketid"] .'&timetrackid='. $val["timetrackid"] .'"><img src="'. $_SWIFT["themepath"] .'icon_ftrash.gif" border="0" /></a></td></tr>
		<tr><td colspan="3"><HR class="notehr"></td></tr>
		<tr class="ticketblrow2"><td colspan="3"><span class="smalltext">'. getProcessedHTML($val["notes"]) .'</span></td></tr><tr class="ticketblrow2"><td colspan="3"><table border="0" cellpadding="3" cellspacing="0" width="100%">';
		$infolist = array();
		$infolist[] = array($_SWIFT["language"]["tworked"], $val["timespent"]);
		$infolist[] = array($_SWIFT["language"]["tbillable"], $val["timebillable"]);
		foreach ($val["fields"] as $fieldkey=>$fieldval)
		{
			unset($fieldvalue);
			if (_is_array($fieldval["fieldvalue"]))
			{
				foreach ($fieldval["fieldvalue"] as $fkey=>$fval)
				{
					$fieldvalue .= htmlspecialchars($fval)."<BR />";
				}
			} else {
				$fieldvalue = htmlspecialchars($fieldval["fieldvalue"]);
			}
			$infolist[] = array($fieldval["title"].":", $fieldvalue);
		}
		renderSplitFields($infolist, "ticketblrow1", "ticketblrow2");
		echo '</table></td></tr></table></div></div></div</td></tr>';
	}
	if (count($_ticket["billing"]))
	{
		$infolist = array();
		echo '<tr><td align="left" valign="top" colspan="8" style="PADDING: 0px 0px 4px 0px;"><div class="ticketcboxpad"><div class="ticketbl"><div class="ticketcbox"><table border="0" cellpadding="0" cellspacing="0" width="100%">';
		$infolist[] = array($_SWIFT["language"]["ttotalworked"], $_ticket["totalworked"]);
		$infolist[] = array($_SWIFT["language"]["ttotalbilled"], $_ticket["totalbilled"]);
		renderSplitFields($infolist, "ticketblrow1", "ticketblrow2");
		echo '</table></div></div></div></td></tr>';
	}

	foreach ($_ticket["fields"] as $key=>$val)
	{
		if ($val["linktype"] == CUSTOMFIELD_TIMETRACK)
		{
			continue;
		}

		echo '<tr><td align="left" valign="top" colspan="8" style="PADDING: 0px 0px 4px 0px;"><div class="ticketcboxpad"><div class="ticketcf"><div class="ticketcbox"><table border="0" cellpadding="0" cellspacing="0" width="100%">
		<tr>
		<td width="100%" align="left"><img src="'. $_SWIFT["themepath"] .'icon_customfield.gif" align="absmiddle" border="0" /><span class="smalltext">&nbsp;'. $val["grouptitle"] .'</span></td><td width="1" align="right">'. iif($val["linktype"]==CUSTOMFIELD_USERTICKET||$val["linktype"]==CUSTOMFIELD_STAFFTICKET||$val["linktype"]==CUSTOMFIELD_STAFFUSERTICKET||$val["linktype"]==CUSTOMFIELD_USER, '<a href="index.php?_m=tickets&_a=ticketactions&action=delcflink&ticketid='. $_ticket["ticketid"] .'&customfieldlinkid='. $val["customfieldlinkid"] .'"><img src="'. $_SWIFT["themepath"] .'icon_ftrash.gif" border="0" /></a>') .'</td></tr>
		<tr><td colspan="2"><HR class="notehr"></td></tr>
		<tr class="ticketcfcontent"><td colspan="2"><table border="0" cellpadding="3" cellspacing="0" width="100%">';
		$colarray = $infolist = array();
		foreach ($val["fields"] as $fieldkey=>$fieldval)
		{
			unset($fieldvalue);
			if (_is_array($fieldval["fieldvalue"]))
			{
				foreach ($fieldval["fieldvalue"] as $fkey=>$fval)
				{
					$fieldvalue .= htmlspecialchars($fval)."<BR />";
				}
			} else {
				$fieldvalue = nl2br(htmlspecialchars($fieldval["fieldvalue"]));
			}
			$infolist[] = array($fieldval["title"].":", autoLink($fieldvalue));
		}
		renderSplitFields($infolist, "ticketcfrow1", "ticketcfrow2");

		echo '</table></td></tr></table></div></div></div></td></tr>';
	}



	addHiddenField("_m", "tickets");
	addHiddenField("_a", "ticketactions");
	addHiddenField("action", "generaltab");
	addHiddenField("ticketlabelid", $_REQUEST["ticketlabelid"]);
	addHiddenField("ticketid", $_ticket["ticketid"]);
	printFormEnd();
	echo '</table><BR /> </div>';
	// ======= END GENERAL TAB =======

	// ======= BEGIN POST REPLY TAB =======
	echo '<div id="tab_ttpostreply" style="DISPLAY: none;" class="tabcontent">';
	printFormStart("replyform", "index.php", "POST", true);

	echo '<table border="0" cellpadding="3" cellspacing="1" width="100%" class="tborder">'.SWIFT_CRLF;

	echo '<tr class="'. getRowBG() .'">
	<td width="100" align="left"><span class="tabletitle">'. $_SWIFT["language"]["from"] .'</span></td>
	<td align="left"><select name="opt_emailqueueid" class="swiftselect">';

	$_queuefrom = false;
	// 1st - Queue Emails
	foreach ($_SWIFT["queuecache"]["list"] as $key=>$val)
	{
		if ($val["departmentid"] == $_ticket["departmentid"])
		{
			$fromname = iif(empty($val["customfromname"]), $_SWIFT["staff"]["fullname"], $val["customfromname"]);
			$fromemail = iif(empty($val["customfromemail"]), $val["email"], $val["customfromemail"]);
			echo '<option value="'. intval($val["emailqueueid"]) .'"'. iif($_ticket["emailqueueid"]==$val["emailqueueid"]," selected") .'>'. htmlspecialchars($fromname) .' &lt;'. htmlspecialchars($fromemail) .'&gt;</option>'.SWIFT_CRLF;
			$_queuefrom = true;
		}
	}

	// Default Return Email
	if (!$_queuefrom)
	{
		echo '<option value="-1" selected>'. htmlspecialchars($_SWIFT["staff"]["fullname"]) .' &lt;'. htmlspecialchars($_SWIFT["settings"]["general_returnemail"]) .'&gt;</option>'.SWIFT_CRLF;
	} else {
		echo '<option value="-1">'. htmlspecialchars($_SWIFT["staff"]["fullname"]) .' &lt;'. htmlspecialchars($_SWIFT["settings"]["general_returnemail"]) .'&gt;</option>'.SWIFT_CRLF;
	}
	
	// 2nd - Personal Email
	echo '<option value="0">'. htmlspecialchars($_SWIFT["staff"]["fullname"]) .' &lt;'. htmlspecialchars($_SWIFT["staff"]["email"]) .'&gt;</option>'.SWIFT_CRLF;
	echo '</select></td></tr>';

	echo '<tr class="'. getRowBG() .'">
	<td width="100" align="left" id="menuref"><span class="tabletitle">'. $_SWIFT["language"]["quickinsert"] .'</span></td>
	<td align="left"><a href="#" title="'. $_SWIFT["qquote"] .'" id="quotelink" onClick="javascript:CustomPopupRef(\'fwquotemenu\', event, \'quotelink\', \'fwquotemenu\', \'menuref\', true);this.blur();" onMouseUp="javascript:this.blur();"><img src="'. $_SWIFT["themepath"] .'icon_quotedrop.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["qquote"] .'&nbsp;<img src="'. $_SWIFT["themepath"] .'menudrop.gif" border="0" align="absmiddle" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" title="'. $_SWIFT["qpredefinedreplies"] .'" id="prcachelink" onClick="javascript:CustomPopupRef(\'prcachemenu\', event, \'prcachelink\', \'prcachemenu\', \'menuref\', prmenuloaded);this.blur();" onMouseUp="javascript:this.blur();"><img src="'. $_SWIFT["themepath"] .'icon_quickinsert.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["qpredefinedreplies"] .'&nbsp;<img src="'. $_SWIFT["themepath"] .'menudrop.gif" border="0" align="absmiddle" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" title="'. $_SWIFT["qknowledgebase"] .'" id="kbcachelink" onClick="javascript:CustomPopupRef(\'kbcachemenu\', event, \'kbcachelink\', \'kbcachemenu\', \'menuref\', kbmenuloaded);this.blur();" onMouseUp="javascript:this.blur();"><img src="'. $_SWIFT["themepath"] .'icon_quickinsert.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["qknowledgebase"] .'&nbsp;<img src="'. $_SWIFT["themepath"] .'menudrop.gif" border="0" align="absmiddle" /></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" title="'. $_SWIFT["qdownloads"] .'" id="dlcachelink" onClick="javascript:CustomPopupRef(\'dlcachemenu\', event, \'dlcachelink\', \'dlcachemenu\', \'menuref\', dlmenuloaded);this.blur();" onMouseUp="javascript:this.blur();"><img src="'. $_SWIFT["themepath"] .'icon_quickinsert.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["qdownloads"] .'&nbsp;<img src="'. $_SWIFT["themepath"] .'menudrop.gif" border="0" align="absmiddle" /></a>&nbsp;&nbsp;&nbsp;</td>
	</tr>';
	echo '<tr class="'. getRowBG() .'">
	<td width="100" align="left"><span class="tabletitle">'. $_SWIFT["language"]["properties"] .'</span></td>
	<td align="left">'. $_SWIFT["language"]["qowner"] .$_poststaffselect.'&nbsp;&nbsp;'. $_SWIFT["language"]["qdepartment"] .str_replace('generalform', 'replyform', $_departmentselect).'&nbsp;&nbsp;'. $_SWIFT["language"]["qstatus"].'<div style="display: inline;" id="updatestatusreplyform"> <img src="'. $_SWIFT["themepath"] .'loadingcircle.gif" id="replyformloading" border="0" align="absmiddle" style="display: none;" /> ' .$_poststatusselect.'</div>&nbsp;&nbsp;'. $_SWIFT["language"]["qpriority"] .$_priorityselect.'&nbsp;&nbsp;</td>
	</tr>';

	printDescRow($_SWIFT["language"]["contents"]);
	$colarray = array();
	$colarray[0]["align"] = "left";
	$colarray[0]["valign"] = "top";
	$colarray[0]["colspan"] = "2";
	$colarray[0]["nowrap"] = true;
	$colarray[0]["value"] = '<textarea style="WIDTH:100%;" name="replycontents" cols="100" rows="15" tabindex="99" onselect="javascript:storeCaret(this);" onclick="javascript:storeCaret(this);" onkeyup="javascript:storeCaret(this);">'. htmlspecialchars(iif(!empty($_ticket["draft"]), $_ticket["draft"], $_POST["replycontents"])) .'</textarea>'.SWIFT_CRLF;
	$colarray[0]["class"] = getRowBG();
	printDataRow($colarray);

	echo '<tr class="'. getRowBG() .'">
	<td align="left" colspan="2"><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td width="160" nowrap><span class="smalltext">'. $_SWIFT["language"]["pdue"] .'<input type="text" name="opt_due" id="f_date_c" size="12" readonly="1" value="" class="swifttext"/>&nbsp;<img src="'. $_SWIFT["themepath"] .'calendar.gif" id="f_trigger_c" style="cursor: pointer;" title="'. $title .'" align="absmiddle"/></span></td><td width="120" nowrap><span class="smalltext">'. $_SWIFT["language"]["ptimeworked"] .'<input type="text" name="opt_timeworked" size="10" value="'. $_SWIFT["language"]["inminutes"] .'" onBlur="if (document.replyform.opt_timebillable.value == \'\'||document.replyform.opt_timebillable.value== \''. $_SWIFT["language"]["inminutes"] .'\') { document.replyform.opt_timebillable.value = this.value; } return true;" onclick="javascript:if(this.value==\''. $_SWIFT["language"]["inminutes"] .'\') { this.value=\'\'; }" class="swifttext"/>&nbsp;</span></td><td width="120" nowrap><span class="smalltext">'. $_SWIFT["language"]["ptimebillable"] .'<input type="text" name="opt_timebillable" size="10" value="'. $_SWIFT["language"]["inminutes"] .'" onclick="javascript:if(this.value==\''. $_SWIFT["language"]["inminutes"] .'\') { this.value=\'\'; }" class="swifttext"/>&nbsp;</span></td><td align="left"><span class="smalltext">&nbsp;&nbsp;&nbsp;&nbsp;<label for="opt_addpred"><input type="checkbox" name="opt_addpred" class="swiftcheckbox" id="opt_addpred" value="1" />&nbsp;&nbsp;<img src="'. $_SWIFT["themepath"] .'icon_plus2.gif" align="absmiddle" border="0" />'.$_SWIFT["language"]["optpred"].'</label>&nbsp;&nbsp;&nbsp;&nbsp;<label for="opt_addkb"><input type="checkbox" name="opt_addkb" class="swiftcheckbox" id="opt_addkb" value="1" />&nbsp;&nbsp;<img src="'. $_SWIFT["themepath"] .'icon_plus2.gif" align="absmiddle" border="0" />'.$_SWIFT["language"]["optkb"].'</label>&nbsp;&nbsp;&nbsp;&nbsp;<label for="opt_sendemail"><input type="checkbox" name="opt_sendemail" class="swiftcheckbox" id="opt_sendemail" value="1" checked />&nbsp;&nbsp;'.$_SWIFT["language"]["optsendemail"].'</label></span></td></tr></table>
	<script type="text/javascript">
    Calendar.setup({
        inputField     :    "f_date_c",
        button         :    "f_trigger_c",
        ifFormat       :    "'. iif($_SWIFT["settings"]["dt_caltype"]=="us", "%m/%d/%Y", "%d/%m/%Y") .'",
        align          :    "Tl",        singleClick    :    true
    });
		isTicketPage = true;
		ticketPageTicketID = "'. $_ticket["ticketid"] .'";
		ticketPageTicketEmail = "'. $_ticket["email"] .'";
	</script>
</td>
	</tr>';

	// ======= ADD NOTE =======
	echo '<tr class="descrow" title="" onmouseover="" onmouseout="" onclick="" id="note1" style="DISPLAY: none;">
<td class="descrow" align="left" valign="top" colspan="2" width="">'. $_SWIFT["language"]["noteoptions"] .'</td>
</tr>
<tr class="row1" title="" onmouseover="" onmouseout="" onclick="" id="note2" style="DISPLAY: none;">
<td class="row1" align="left" valign="top" colspan=""><span class="tabletitle">'.$_SWIFT["language"]["notetype"].'</span></td>
<td class="row1" align="left" valign="top" colspan=""><label for="notetype[0]"><input type="radio" id="notetype[0]" name="notetype" value="'. NOTE_TICKET .'" checked /> <span class="smalltext">'. $_SWIFT["language"]["ticket"] .'</label></span>

<label for="notetype[1]"><input type="radio" id="notetype[1]" name="notetype" value="'. NOTE_USER .'" /> <span class="smalltext">'. $_SWIFT["language"]["user"] .'</label></span>
</td>
</tr>
<tr class="row2" title="" onmouseover="" onmouseout="" onclick="" id="note3" style="DISPLAY: none;">
<td class="row1" align="left" valign="top" colspan="2" width=""><textarea style="WIDTH:100%;" name="notecontents" cols="100" rows="3">'. htmlspecialchars($_POST["notecontents"]) .'</textarea>
</td>
</tr>';

	// ======= EMAIL OPTIONS =======
	echo '<tr class="descrow" title="" onmouseover="" onmouseout="" onclick="" id="emailopt1" style="DISPLAY: none;">
<td class="descrow" align="left" valign="top" colspan="2" width="">'. $_SWIFT["language"]["emailoptions"] .'</td>
</tr>

<tr class="row1" title="" onmouseover="" onmouseout="" onclick="" id="emailopt2" style="DISPLAY: none;">
<td class="row1" align="left" valign="top" colspan=""><span class="tabletitle">'.$_SWIFT["language"]["eocc"].'</span></td>
<td class="row1" align="left" valign="top" colspan=""><input type="text" name="opt_cc" value="" size="35" class="swifttext" />&nbsp;&nbsp;( <span class="smalltext"><label for="ccaddrecpients"><input type="checkbox" id="ccaddrecpients" name="ccaddrecpients" value="1" /> '. $_SWIFT["language"]["addtorecp"] .'</label> )</span>&nbsp;&nbsp;<a href="javascript:popupInfoWindow(\''. $_SWIFT["swiftpath"] .'staff/index.php?_m=core&_a=userlookup&formname=replyform&formfield=opt_cc&sessionid='. $_SWIFT["session"]["sessionid"] .'\');"><img src="'. $_SWIFT["themepath"] .'icon_searchlookup.gif" title="'. $_SWIFT["language"]["lookup"] .'" border="0" align="absmiddle" /></a>
</td>
</tr>
<tr class="row2" title="" onmouseover="" onmouseout="" onclick="" id="emailopt3" style="DISPLAY: none;">
<td class="row2" align="left" valign="top" colspan=""><span class="tabletitle">'.$_SWIFT["language"]["eobcc"].'</span></td>
<td class="row2" align="left" valign="top" colspan=""><input type="text" name="opt_bcc" value="" size="35" class="swifttext" />&nbsp;&nbsp;( <span class="smalltext"><label for="bccaddrecpients"><input type="checkbox" id="bccaddrecpients" name="bccaddrecpients" value="1" /> '. $_SWIFT["language"]["addtorecp"] .'</label> )</span>&nbsp;&nbsp;<a href="javascript:popupInfoWindow(\''. $_SWIFT["swiftpath"] .'staff/index.php?_m=core&_a=userlookup&formname=replyform&formfield=opt_bcc&sessionid='. $_SWIFT["session"]["sessionid"] .'\');"><img src="'. $_SWIFT["themepath"] .'icon_searchlookup.gif" title="'. $_SWIFT["language"]["lookup"] .'" border="0" align="absmiddle" /></a>
</td>
</tr>';

	// ======= ATTACH FILES =======
	$attachrowjs = "switchDisplay('attach0');";
	echo '<tr class="descrow" title="" onmouseover="" onmouseout="" onclick="" id="attach0" style="DISPLAY: none;">
<td class="descrow" align="left" valign="top" colspan="2" width="">'. $_SWIFT["language"]["attachfile"] .'</td>
</tr>';

$index = 1;
if (empty($_SWIFT["settings"]["t_maxattach"]))
{
	$maxattach = 3;
} else {
	$maxattach = intval($_SWIFT["settings"]["t_maxattach"]);
}

for ($ii=0; $ii<$maxattach; $ii++)
{
	$rowclass = getRowBG();
	$attachrowjs .= "switchDisplay('attach". $index ."');";
	echo '<tr class="'. $rowclass .'" title="" onmouseover="" onmouseout="" onclick="" id="attach'. $index .'" style="DISPLAY: none;">
<td class="'. $rowclass .'" align="left" valign="top" colspan=""><span class="tabletitle">'.sprintf($_SWIFT["language"]["attachfilen"], $index).'</span></td>
<td class="'. $rowclass .'" align="left" valign="top" colspan=""><input type="file" name="opt_file['. $index .']" value="" size="35" class="swifttext" />
</td>
</tr>';
	$index++;
}

	// ======= DOWNLOADS LINK =======
	echo '<tr class="descrow" title="" onmouseover="" onmouseout="" onclick="" id="downloads1" style="DISPLAY: none;">
<td class="descrow" align="left" valign="top" colspan="2" width="">'. $_SWIFT["language"]["qdownloads"] .'</td>
</tr>

<tr class="row1" title="" onmouseover="" onmouseout="" onclick="" id="downloads2" style="DISPLAY: none;">
<td class="row1" align="left" valign="top" colspan="2"><table border="0" cellpadding="3" cellspacing="1" width="100%"><tr><td width="400" align="left"><select name="opt_downloads[]" class="swiftselect" size="5" style="WIDTH: 100%;" multiple></select></td><td align="left" valign="middle"><input type="button" onClick="javascript:removeDLItem();" class="bluebuttonsuperbig" value="'. $_SWIFT["language"]["removefile"] .'" /><BR /><BR /><BR /><input type="button" class="bluebuttonsuperbig" onClick="javascript:clearDLItems();" value="'. $_SWIFT["language"]["cancel"] .'" /></td></tr></table>
</td>
</tr>
';

	if ($_SWIFT["settings"]["t_reciplist"] == "1")
	{
		$_recipients = $_ticketobj->getRecipients();
		foreach ($_recipients as $key=>$val)
		{
			if ($val["recipienttype"] == RECIPIENT_THIRDPARTY)
			{
				$img = "img_blockthirdparty.gif";
			} else if ($val["recipienttype"] == RECIPIENT_CCUSER) {
				$img = "img_blockccuser.gif";
			} else if ($val["recipienttype"] == RECIPIENT_BCCUSER) {
				$img = "img_blockbccuser.gif";
			}
			
			$data = array();
			$data[0]["value"] = '<table border="0" cellpadding="2" cellspacing="1" width="100%"><tr class="'. getRowBG() .'"><td width="1" align="left"><img src="'. $_SWIFT["themepath"].$img .'" border="0" /></td><td align="left><span class="smalltext">'. htmlspecialchars($val["email"]) .'</span></td></tr></table>'.SWIFT_CRLF;
			$data[0]["align"] = "left";
			$data[0]["colspan"] = "2";
			printDataRow($data);
		}
	}


	echo '<tr class="descrow" id="prdescfollowup" title="" onmouseover="" onmouseout="" onclick="" style="display:none;">
<td class="descrow" align="left" valign="top" colspan="2" width="">'. $_SWIFT["language"]["tabfollowup"] .'</td>
</tr>
<tr class="row1" id="prfollowupstoredisp" style="display:none;">
<td class="row1" align="left" id="prfollowupstore" valign="top" colspan="2"><span class="smalltext"><img src="'. $_SWIFT["themepath"] .'loadingcircle.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["loading"] .'</span></td>
</tr>';


	echo '<tr class="row1" id="ticketpostlocktr" style="display: none;">
<td class="row1" align="left" valign="top" colspan="2"><div class="ticketpostlockui" id="ticketpostlockui"></div></td>
</tr>';

	$data[0]["value"] = '<input type="submit" class="yellowbuttonbig" onClick="javascript:processReplyForm();" value="'. $_SWIFT["language"]["send"] .'" tabindex="100" />&nbsp;&nbsp;<input type="submit" class="bluebuttonsuperbig" value="'. $_SWIFT["language"]["saveasdraft"] .'" onClick="javascript:document.replyform.saveasdraft.value=\'2\';" />&nbsp;&nbsp;<input type="button" onClick="javascript:renderFollowUpSubSection(\'reply\', \''. $_ticket["ticketid"] .'\');" class="bluebuttonbig" value="'. $_SWIFT["language"]["tabfollowup"] .'" />&nbsp;&nbsp;<input type="button" onClick="javascript:switchDisplay(\'note1\');switchDisplay(\'note2\');switchDisplay(\'note3\');" class="bluebuttonbig" value="'. $_SWIFT["language"]["addnote"] .'" />&nbsp;&nbsp;<input type="button" onClick="javascript:switchDisplay(\'emailopt1\');switchDisplay(\'emailopt2\');switchDisplay(\'emailopt3\');" class="bluebuttonsuperbig" value="'. $_SWIFT["language"]["emailoptions"] .'" />&nbsp;&nbsp;<input type="button" onClick="'. $attachrowjs .'" class="bluebuttonbig" value="'. $_SWIFT["language"]["attachfile"] .'" />&nbsp;&nbsp;<input type="button" onClick="javascript:openSpellChecker();" class="bluebuttonbig" value="'. $_SWIFT["language"]["spellcheck"] .'" />&nbsp;&nbsp;'.SWIFT_CRLF;
	$data[0]["align"] = "left";
	$data[0]["colspan"] = 2;
	printDataRow($data);

	addHiddenField("_m", "tickets");
	addHiddenField("_a", "ticketactions");
	addHiddenField("action", "reply");
	addHiddenField("saveasdraft", "1");
	addHiddenField("ticketlabelid", $_REQUEST["ticketlabelid"]);
	addHiddenField("ticketid", $_ticket["ticketid"]);
	echo '</table>';
	printFormEnd();
	echo '<BR /></div>';
	// ======= END POST REPLY TAB =======


	// ======= BEGIN TICKET HISTORY TAB =======
	echo '<div id="tab_ttaddnotes" style="DISPLAY: none;" class="tabcontent"><table border="0" cellpadding="3" cellspacing="1" width="100%" class="tborder"><tr><td class="row1"><span class="smalltext"><img src="'. $_SWIFT["themepath"] .'loadingcircle.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["loading"] .'</span></td></tr></table><BR /> </div>';
	// ======= END TICKET HISTORY TAB =======

	// ======= BEGIN TICKET HISTORY TAB =======
	echo '<div id="tab_tthistory" style="DISPLAY: none;" class="tabcontent"><table border="0" cellpadding="3" cellspacing="1" width="100%" class="tborder"><tr><td class="row1"><span class="smalltext"><img src="'. $_SWIFT["themepath"] .'loadingcircle.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["loading"] .'</span></td></tr></table><BR /> </div>';
	// ======= END TICKET HISTORY TAB =======

	// ======= BEGIN AUDIT LOG TAB =======
	echo '<div id="tab_ttlog" style="DISPLAY: none;" class="tabcontent"><table border="0" cellpadding="3" cellspacing="1" width="100%" class="tborder"><tr><td class="row1"><span class="smalltext"><img src="'. $_SWIFT["themepath"] .'loadingcircle.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["loading"] .'</span></td></tr></table><BR /> </div>';
	// ======= END AUDIT LOG TAB =======

	// ======= BEGIN FORWARD TAB =======
	echo '<div id="tab_ttforward" style="DISPLAY: none;" class="tabcontent"><table border="0" cellpadding="3" cellspacing="1" width="100%" class="tborder"><tr><td class="row1"><span class="smalltext"><img src="'. $_SWIFT["themepath"] .'loadingcircle.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["loading"] .'</span></td></tr></table><BR /> </div>';
	// ======= END FORWARD TAB =======

	// ======= BEGIN FOLLOWUP TAB =======
	echo '<div id="tab_ttfollowup" style="DISPLAY: none;" class="tabcontent"><table border="0" cellpadding="3" cellspacing="1" width="100%" class="tborder"><tr><td class="row1"><span class="smalltext"><img src="'. $_SWIFT["themepath"] .'loadingcircle.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["loading"] .'</span></td></tr></table><BR /> </div>';
	// ======= END FOLLOWUP TAB =======

	// ======= BEGIN RELEASE TAB =======
	echo '<div id="tab_ttrelease" style="DISPLAY: none;" class="tabcontent"><table border="0" cellpadding="3" cellspacing="1" width="100%" class="tborder"><tr><td class="row1"><span class="smalltext"><img src="'. $_SWIFT["themepath"] .'loadingcircle.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["loading"] .'</span></td></tr></table><BR /> </div>';
	// ======= END RELEASE TAB =======

	// ======= BEGIN EDIT TAB =======
	echo '<div id="tab_ttedit" style="DISPLAY: none;" class="tabcontent"><table border="0" cellpadding="3" cellspacing="1" width="100%" class="tborder"><tr><td class="row1"><span class="smalltext"><img src="'. $_SWIFT["themepath"] .'loadingcircle.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["loading"] .'</span></td></tr></table><BR /> </div>';
	// ======= END EDIT TAB =======

	// ======= BEGIN CHATS TAB =======
	echo '<div id="tab_ttlschats" style="DISPLAY: none;" class="tabcontent"><table border="0" cellpadding="3" cellspacing="1" width="100%" class="tborder"><tr><td class="row1"><span class="smalltext"><img src="'. $_SWIFT["themepath"] .'loadingcircle.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["loading"] .'</span></td></tr></table><BR /> </div>';
	// ======= END CHATS TAB =======

	// ======= BEGIN BILLING TAB =======
	echo '<div id="tab_ttbilling" style="DISPLAY: none;" class="tabcontent"><table border="0" cellpadding="3" cellspacing="1" width="100%" class="tborder"><tr><td class="row1"><span class="smalltext"><img src="'. $_SWIFT["themepath"] .'loadingcircle.gif" border="0" align="absmiddle" />&nbsp;'. $_SWIFT["language"]["loading"] .'</span></td></tr></table><BR /> </div>';
	// ======= END BILLING TAB =======

	echo '</td></tr></table>';



	/**
	* ###############################################
	* BEGIN POST RENDERING
	* ###############################################
	*/
	// ======= START PAGINATION TABLE =======

	$_limit = intval($_SWIFT["settings"]["t_postlimit"]);
	if (!$_limit)
	{
		$_limit = "6";
	}

	// Get the current offset for this page
	if (!empty($_REQUEST["offset"]) && is_numeric($_REQUEST["offset"]))
	{
		$_offset = intval($_REQUEST["offset"]);
	} else {
		$_offset = "0";
	}

	$totalreplies = $_ticket["totalreplies"];
	if ($_SWIFT["settings"]["t_enpagin"] != 1)
	{
		$_limit = false;
		$_offset = false;
		$totalreplies = 0;
	}

	if ($_REQUEST["viewall"] == 1)
	{
		$_posts = $_ticketobj->getTicketPosts(-1, 0, $_SWIFT["settings"]["t_postorder"]);
	} else {
		$_posts = $_ticketobj->getTicketPosts($_limit, $_offset, $_SWIFT["settings"]["t_postorder"]);
	}


	$pagination = pagination("index.php?_m=tickets&_a=viewticket&ticketid=".intval($_ticket["ticketid"]).iif(!empty($_GET["highlight"]), "&highlight=".urlencode($_GET["highlight"])).iif(!empty($_REQUEST["ticketlabelid"]), "&ticketlabelid=".intval($_REQUEST["ticketlabelid"])).iif(!empty($_REQUEST["ticketsearchid"]), "&ticketsearchid=".intval($_REQUEST["ticketsearchid"])), ($totalreplies+1), $_limit, $_offset, "5", "pageoftotal", TRUE, FALSE, TRUE, FALSE, TRUE);

	$pagination1 = '<table width="100%" border="0" cellspacing="0" cellpadding="0">'.SWIFT_CRLF;
	$pagination2 = '<tr><td><table width="100%"  border="0" cellspacing="0" cellpadding="0" id="tmenuref"><tr valign="top"><td align="left"><table border="0" cellpadding="0" cellspacing="1" class="tborder"><tr>'.$pagination.'</tr></table></td><td align="right" width="1"><table border="0" cellpadding="0" cellspacing="1" class="tborder"><tr>'.iif(!empty($_ticket["slaplanid"]), '<td class="navpageselected" nowrap><img src="'. $_SWIFT["themepath"] .'icon_sla.gif" align="absmiddle"> '. sprintf($_SWIFT["language"]["slalabel"], htmlspecialchars($_SWIFT["slaplancache"][$_ticket["slaplanid"]]["title"])) .'</td>').iif(!empty($_ticket["tgroupid"]), '<td class="navpageselected" nowrap><img src="'. $_SWIFT["themepath"] .'icon_templategroup.gif" align="absmiddle"> '. sprintf($_SWIFT["language"]["tgroup"], htmlspecialchars($_SWIFT["tgroupcache"][$_ticket["tgroupid"]]["title"])) .'</td>'). '<td class="navpageselected" nowrap><a href="index.php?_m=tickets&_a=ticketactions&action=jump&t=previous&ticketid='. intval($_ticket["ticketid"]) .'" title="'. $_SWIFT["language"]["previousticket"] .'">'. $_SWIFT["language"]["previousticket"] .'</a></td>'.'<td class="navpageselected" nowrap><a href="index.php?_m=tickets&_a=ticketactions&action=jump&t=next&ticketid='. intval($_ticket["ticketid"]) .'" title="'. $_SWIFT["language"]["nextticket"] .'">'. $_SWIFT["language"]["nextticket"] .'</a></td></tr></table></td></tr></table></tr></td>'.SWIFT_CRLF;
	$pagination3 = '<tr><td><img src="'. $_SWIFT["themepath"] .'space.gif" width="1" height="6" /></td></tr>'.SWIFT_CRLF;
	$pagination4 .= '</table>';
	echo $pagination1.$pagination2.$pagination3.$pagination4;
	$footerpagination = $pagination1.$pagination3.$pagination2.$pagination4;
	unset($pagination1); unset($pagination2); unset($pagination3); unset($pagination4);

	echo '<table cellpadding="0" cellspacing="0" border="0" width="100%" class="tborder">'.SWIFT_CRLF;
	echo '<thead>'.SWIFT_CRLF;
	echo '<tr>'.SWIFT_CRLF;
	echo '<td class="tcat" width="160" align="left" nowrap><table cellpadding="0" cellspacing="0" border="0" width="160"><tr><td width="1" class="tcat"><img src="'. $_SWIFT["themepath"] .'space.gif" width="4" height="21"></td><td align="left" class="tcat">'.$_SWIFT["language"]["author"] .'</td></tr></table></td>'.SWIFT_CRLF;
	echo '<td bgcolor="#FFFFFF" width="1" align="left" nowrap><img src="'. $_SWIFT["themepath"] .'space.gif" width="1" height="21"></td>'.SWIFT_CRLF;
	echo '<td class="tcat" align="left" width="100%" nowrap><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td width="1" class="tcat"><img src="'. $_SWIFT["themepath"] .'space.gif" width="4" height="21"></td><td align="left" class="tcat">'. $_SWIFT["language"]["contents"] .'</td></tr></table></td>'.SWIFT_CRLF;
	echo '</tr>'.SWIFT_CRLF;
	echo '</thead>'.SWIFT_CRLF;
	echo '<tbody><tr><td class="contenttableborder" colspan="'. "3" .'"><table border="0" cellpadding="0" cellspacing="1" width="100%">'.SWIFT_CRLF;

	// ======= SEARCH HIGHLIGHTING =======
	$dohighlight = false;
	if (!empty($_GET["highlight"]))
	{
		$_highlight = explode(" ", $_GET["highlight"]);
		if (!count($_highlight))
		{
			$_highlight = array();
			$_highlight[] = $_GET["highlight"];
		}
		$dohighlight = true;
	}

	$rowclass = "ticketrow2";
	// Process the Posts Now.
	foreach ($_posts as $key=>$val)
	{
		if ($rowclass == "ticketrow2")
		{
			$rowclass = "ticketrow1";
		} else {
			$rowclass = "ticketrow2";
		}

		if ($_ticket["isphonecall"] == "1" && $_ticket["firstpostid"] == $val["ticketpostid"])
		{
			$val["phoneticket"] = true;
		}
		?>
		<tr> 
		<td align="left" valign="top" class="<?=$rowclass?>" width="160"><table width="100%" border="0" cellspacing="0" cellpadding="4" height="100%">
		<tr> 
		<td><span class="mediumtitle"><strong><?=htmlspecialchars($val["fullname"])?></strong></span><br><br>
		<?
		if ($val["creator"] == POST_STAFF)
		{
			?><img src="<?=$_SWIFT["themepath"]?>img_staff.gif" border="0" /><?
		} else if ($val["creator"] == POST_THIRDPARTY) {
			?><img src="<?=$_SWIFT["themepath"]?>img_thirdparty.gif" border="0" /><?
		} else if ($val["creator"] == POST_RECIPIENT) {
			?><img src="<?=$_SWIFT["themepath"]?>img_recipient.gif" border="0" /><?
		} else {
			?><img src="<?=$_SWIFT["themepath"]?>img_user.gif" border="0" /><?
		}
		?>
		</td></tr></table></td>

		<td align="left" valign="top" class="<?=$rowclass?>"><table width="100%" border="0" cellspacing="0" cellpadding="3">
		<tr><td>
		<table width="100%" border="0" cellspacing="0" cellpadding="2"><tr><td width="1"><img src="<?
		if ($val["phoneticket"] == true) {
			echo $_SWIFT["themepath"]."icon_ticketphone.gif";
		} else if ($val["dateline"] > $_SWIFT["staff"]["lastvisit"]) {
			echo $_SWIFT["themepath"]."icon_email.gif";
		} else {
			echo $_SWIFT["themepath"]."icon_emailopen.gif";
		}
		?>" align="absmiddle" border="0" /></td><td align="left"><span class="smalltext"><?=sprintf($_SWIFT["language"]["trdate"], edate($_SWIFT["settings"]["dt_datetimeformat"], $val["dateline"]))?></span></td><td align="right" width="50"><a href="#" onClick="javascript:autoInsertTP(<?=intval($val["ticketpostid"])?>, 'reply');" title="<?=$_SWIFT["language"]["quote"]?>"><img src="<?=$_SWIFT["themepath"]?>icon_quote.gif" border="0" /></a></td></tr></table>
		<hr class="tickethr" size="1">
		<span class="mediumtext">
		<?
		$contents = &$val["contents"];
		if ($dohighlight)
		{
			echo str_highlight($contents, $_highlight, STR_HIGHLIGHT_SIMPLE|STR_HIGHLIGHT_WHOLEWD, '<span class="searchighlight">\1</span>');
		} else {
			echo $contents;
		}
		if (count($val["attachments"]))
		{
			?><BR /><BR /><fieldset class="swiftfieldsetnopad"><legend><?=$_SWIFT["language"]["attachments"]?></legend><div class="navsub"><?
			foreach ($val["attachments"] as $atkey=>$atval)
			{
				$extension = getFileExtension($atval["filename"]);
				$mimedata = $mimelist[$extension];
				if (!empty($mimedata[1]))
				{
					$icon = $mimedata[1];
				} else {
					$icon = "mimeico_blank.gif";
				}
				echo '<span class="smalltext"><a href="index.php?_m=tickets&_a=ticketactions&ticketid='. intval($_ticket["ticketid"]) .'&action=attachment&attachmentid='. intval($atval["attachmentid"]) .'" target="_blank"><img src="'. $_SWIFT["themepath"] . $icon .'" border="0" align="absmiddle" />&nbsp;'. $atval["filename"] .'</a> ('. formattedSize($atval["filesize"]) .')<BR /></span>'.SWIFT_CRLF;
			}
			?></div></fieldset><?
		}
		if ($val["edited"] == 1)
		{
			echo '<BR /><span class="smalltext"><i>'.sprintf($_SWIFT["language"]["lastedited"], $_SWIFT["staffcache"][$val["editedbystaffid"]]["fullname"], edate($_SWIFT["settings"]["dt_datetimeformat"], $val["editeddateline"]))."</i></span><BR />";
		}
		?>
		</span>
		</td>
		</tr>
		</table></td></tr>

		<tr class="<?=$rowclass?>">
		<td align="left" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="3">
		<tr>
		<td><span class="smalltext"><a href="javascript:popupDataWindow('index.php?_m=tickets&_a=ticketactions&ticketid=<?=$_ticket["ticketid"]?>&action=options&type=print&ticketpostid=<?=$val["ticketpostid"]?>');" title="<?=$_SWIFT["language"]["printpost"]?>"><img src="<?=$_SWIFT["themepath"]?>icon_fprint.gif" border="0" /></a><?
		if ($val["isemailed"] == 1)
		{
		?>&nbsp;<a href="javascript:popupDataWindow('index.php?_m=tickets&_a=ticketactions&ticketid=<?=$_ticket["ticketid"]?>&action=options&type=headers&ticketpostid=<?=$val["ticketpostid"]?>');" title="<?=$_SWIFT["language"]["viewheaders"]?>"><img src="<?=$_SWIFT["themepath"]?>icon_fheaders.gif" border="0" /></a><?
		}
		if ($_SWIFT["staff"]["teditpost"] != "0")
		{
		?>&nbsp;<a href="javascript:popupDataWindow('index.php?_m=tickets&_a=editticketpost&ticketid=<?=$_ticket["ticketid"]?>&ticketpostid=<?=$val["ticketpostid"]?>')"><img src="<?=$_SWIFT["themepath"]?>icon_fedit.gif" border="0" title="<?=$_SWIFT["language"]["editpost"]?>" /></a><?} if ($_SWIFT["staff"]["tdeletepost"] != "0") {?>&nbsp;<a href="#" title="<?=$_SWIFT["language"]["deletepost"]?>" onClick="javascript:doConfirm('<?=$_SWIFT["language"]["postdelmsg"]?>', 'index.php?_m=tickets&_a=ticketactions&ticketid=<?=$_ticket["ticketid"]?>&action=options&type=deletepost&ticketpostid=<?=$val["ticketpostid"]?>');"><img src="<?=$_SWIFT["themepath"]?>icon_ftrash.gif" border="0" /></a><?}?>&nbsp;</span></td>
		</tr></table></td>
		<td height="0" align="left" valign="top" bgcolor="<?=$color?>"><table width="100%" border="0" cellspacing="0" cellpadding="6">
		<tr>
		<td align="left" width="50%"><span class="smalltext"><?
		if (!empty($val["emailto"]))
		{
			echo sprintf($_SWIFT["language"]["trtoemail"], htmlspecialchars($val["emailto"]))."&nbsp;&nbsp;&nbsp;";
		}
		if ($val["phoneticket"] == true)
		{
			echo sprintf($_SWIFT["language"]["trphone"], htmlspecialchars($_ticket["phoneno"]))."&nbsp;&nbsp;&nbsp;";
		}
		if (!empty($val["email"]))
		{
			echo sprintf($_SWIFT["language"]["tremail"], htmlspecialchars($val["email"]));
		}
		?></span></td><td align="right" width="50%"><span class="smalltext"><?
		if (!empty($val["ipaddress"]))
		{
			echo sprintf($_SWIFT["language"]["trip"], htmlspecialchars($val["ipaddress"]));
		}
		?></span></td>
		</tr>
		</table></td></tr>
		<?
	}
	echo '</table></td></tr></tbody></table>'.SWIFT_CRLF;

	echo $footerpagination;

	$template->assign("backurl", "index.php?_m=tickets&_a=manage" .iif(!empty($_REQUEST["departmentid"]), "&departmentid=". intval($_REQUEST["departmentid"])) .iif(!empty($_REQUEST["ticketstatusid"]), "&ticketstatusid=". intval($_REQUEST["ticketstatusid"])) .iif(!empty($_REQUEST["ticketsearchid"]), "&ticketsearchid=".intval($_REQUEST["ticketsearchid"])).iif(!empty($_REQUEST["ticketlabelid"]), "&ticketlabelid=".intval($_REQUEST["ticketlabelid"])));
	$interface->staffFooter();

	$seconds = fetchmicrotime()-$_SWIFT["starttime"];
	//$dbCore->debugOutput();
	//echo $seconds;
}


?>